# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=hunspell-en
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2020.12.07
pkgrel=1
pkgdesc="Hunspell dictionaries (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://wordlist.sourceforge.io/"
license=('LGPL' 'custom:scowl')
makedepends=("unzip")
optdepends=(${MINGW_PACKAGE_PREFIX}-hunspell)
source=(https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_US-large-$pkgver.zip
        https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_AU-large-$pkgver.zip
        https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_CA-large-$pkgver.zip
        https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_GB-large-$pkgver.zip)
sha256sums=('5a93617312ffb7cccc54c8fd8a3e6712eb0e9cd4a69f1d358b82eb4d352072b7'
            '496e477ae7b018c7be360e60aaa2f98e7f1c97c7892df93b2457112424c61e31'
            '4634489086f64037af7aaa4bca8d6ce17f7442b662632956e5dd4c094f87beea'
            'f86beb77228c737c8c69468ffc4ea067512872278869b98a5d3ec18f125107bd')

build() {
  /bin/true
}

package() {
  cd "$srcdir"
  install -dm755 ${pkgdir}${MINGW_PREFIX}/share/hunspell
  install -m644 en_*.dic en_*.aff ${pkgdir}${MINGW_PREFIX}/share/hunspell

  pushd ${pkgdir}${MINGW_PREFIX}/share/hunspell/
    en_GB_aliases="en_AG en_BS en_BW en_BZ en_DK en_GH en_HK en_IE en_IN en_JM en_NA en_NG en_NZ en_SG en_TT en_ZA en_ZW"
    for lang in $en_GB_aliases; do
      ln -s en_GB-large.aff $lang.aff
      ln -s en_GB-large.dic $lang.dic
    done

    en_AU_aliases="en_AU"
    for lang in $en_AU_aliases; do
      ln -s en_AU-large.aff $lang.aff
      ln -s en_AU-large.dic $lang.dic
    done

    en_US_aliases="en_PH en_US"
    for lang in $en_US_aliases; do
      ln -s en_US-large.aff $lang.aff
      ln -s en_US-large.dic $lang.dic
    done
    larges="en_CA en_GB"
    for lang in $larges; do
      mv $lang-large.aff $lang.aff
      mv $lang-large.dic $lang.dic
    done
  popd

  # the symlinks
  install -dm755 ${pkgdir}${MINGW_PREFIX}/share/myspell/dicts
  pushd ${pkgdir}${MINGW_PREFIX}/share/myspell/dicts
    for file in ${pkgdir}${MINGW_PREFIX}/share/hunspell/*; do
      ln -sv ${pkgdir}${MINGW_PREFIX}/share/hunspell/$(basename $file) .
    done
  popd

  # docs
  install -dm755 ${pkgdir}${MINGW_PREFIX}/share/doc/$_realname
  install -m644 README_en_??-large.txt ${pkgdir}${MINGW_PREFIX}/share/doc/$_realname

  # licenses
  install -D -m644 README_en_AU-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_AU
  install -D -m644 README_en_US-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_US
  install -D -m644 README_en_CA-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_CA
  install -D -m644 README_en_GB-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_GB
}
